<?php

namespace App\Http\Requests\Api;

class LoginRequest extends ApiRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return $this->is('*/com/login') ? [
            'username' => 'required',
            'password' => 'required|between:6,60',
            'wx_code' => 'required_if:type,js_personal,js_company,ios_personal,ios_company,android_personal,android_company',
            'encrypted_data' => 'required_if:type,js_personal,js_company',
            'iv' => 'required_if:type,js_personal,js_company',
            'qq_access_token' => 'required_if:type,ios_qq_personal,ios_qq_company,android_qq_personal,android_qq_company'
        ] : [
            'account' => 'required',
            'password' => 'required|between:6,60',
            'wx_code' => 'required_if:type,js_personal,js_company,ios_personal,ios_company,android_personal,android_company',
            'encrypted_data' => 'required_if:type,js_personal,js_company',
            'iv' => 'required_if:type,js_personal,js_company',
            'qq_access_token' => 'required_if:type,ios_qq_personal,ios_qq_company,android_qq_personal,android_qq_company'
        ];
    }

    public function attributes()
    {
        return [
            'account' => '用户名或手机号',
            'username' => '用户名或手机号',
            'password' => '密码',
        ];
    }

    public function messages()
    {
        return array_merge(parent::messages(), [
            'password.between' => ':attribute长度需:min~:max个字',
        ]);
    }

}
